VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Frm_States 
   Caption         =   "StatesSelect"
   ClientHeight    =   4740
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5340
   OleObjectBlob   =   "Frm_States.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "Frm_States"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private TempFold As String
Private stateName() As String
Private CalKit() As Integer
Private myIniFileName As String
Private StatesPath As String
Dim ServerIP As String
Dim UserName As String
Dim UserPassWord As String
Private BackStates As String
Dim iniPath As String

Private Sub StatesList_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    
    Call Frm_States.Move(-300, 0)
    DoEvents
    Dim myStatesFile As New CIniFile
    Dim strFileLocal As String, strFileRemote As String
    Dim dwType As Integer
    Dim bRet As Boolean
    Dim i As Integer
    Dim tempStates() As String
    Dim allFile() As String
    
    strFileRemote = StatesList.list(StatesList.ListIndex)
    strFileLocal = TempFold + strFileRemote
    'down load ini file
    bRet = GetFTPFile(hConnect, iniPath + strFileRemote, TempFold + strFileRemote)
    If bRet = False Then
        MsgBox "Can not read ini file!", vbOKOnly + vbCritical, "Error!"
    End If
    StatesList.Clear
    FTPClose hConnect
    
    'open states ftp
    hConnect = FTPOpen(ServerIP, UserName, UserPassWord, allFile, StatesPath)
    myIniFileName = strFileLocal
    'get states file name,and kill ini file
    Call ReadState
    'get states file
    For i = 0 To UBound(stateName)
        tempStates = Split(stateName(i), "\")
        bRet = GetFTPFile(hConnect, StatesPath + tempStates(UBound(tempStates)), BackStates + tempStates(UBound(tempStates)))
        If bRet = False Then
            MsgBox "Can't download State files!", vbOKOnly + vbCritical, "Error!"
        Else
            Frm_UpData.UpBarProgress ((i + 1) / (UBound(stateName) + 1))
        End If
    Next i
    FTPClose hConnect
    Unload Frm_States

End Sub

Private Sub UserForm_Initialize()
    
    Dim FTPFile As New CIniFile
    
    Dim allFile() As String
    
    Call FTPFile.SpecifyIni("D:\ATE\Config\webConfig.ini")
    ServerIP = FTPFile.ReadString("FTP", "ServerIP", 20)
    UserName = FTPFile.ReadString("FTP", "UserName", 20)
    UserPassWord = FTPFile.ReadString("FTP", "UserPassWord", 20)
    TempFold = FTPFile.ReadString("FTP", "TempFold", 30)
    iniPath = FTPFile.ReadString("Path", "Config", 60)
    StatesPath = FTPFile.ReadString("Path", "States", 60)
    BackStates = FTPFile.ReadString("Path", "BackStates", 120)
    Dim fileString() As String
    'open ini FTP
    hConnect = FTPOpen(ServerIP, UserName, UserPassWord, allFile, iniPath)
    For i = 0 To UBound(allFile)
        StatesList.AddItem allFile(i)
    Next i

    
End Sub

Private Function ReadState()
    
    Dim temp As String
    Open myIniFileName For Input As #1
    Input #1, temp
    StateNum = Split(temp, "=")(1)
    ReDim stateName(StateNum - 1) As String
    ReDim CalKit(StateNum - 1) As Integer
    For i = 0 To StateNum - 1
        Input #1, stateName(i), CalKit(i)
        If CalKit(i) > 8 Or CalKit(i) < 1 Then
            MsgBox "The " & (i + 1) & " " & "Cal Kit Number is out of range,Please Check ini File!", vbOKOnly + vbCritical, "Error!"
            End
        End If
    Next i
    
    Close #1
    'kill ini file
    If Len(Dir(myIniFileName)) <> 0 Then
        Kill myIniFileName
    End If
    
End Function
